import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xvideos/assets_tool/images.dart';

final holidayTheme = HolidayTheme();
var dayMap = {
  '默认': 1,
  '清明节': 2,
  '端午节': 3,
  '劳动节': 4,
};

final String appIcon = 'appIcon';

class HolidayTheme {
  static final HolidayTheme _instance = HolidayTheme._internal();

  factory HolidayTheme() {
    return _instance;
  }

  HolidayTheme._internal();

  int themeValue = 1;

  static HolidayThemeModel get theme => _instance._model;

  bool get openHoliday => themeValue > 1; //是否打开节假日

  HolidayThemeModel _model = HolidayThemeModel();

  setThemeValue(String festival) {
    themeValue = dayMap[festival] ?? 1;
    String path = "$themeValue/";

    _model.current = themeValue;
    _model.appIcon = "${path}ic_launcher.webp".holidayPath;

    _model.searchBgImg = "${path}search_bg.webp".holidayPath;
    _model.addPublish = "${path}publish.webp".holidayPath;
    _model.vipBg = "${path}mine_vip_bg.webp".holidayPath;

    _model.coin = "${path}mine_gold_enter.webp".holidayPath;
    _model.agent = "${path}mine_agent_enter.webp".holidayPath;
    _model.aiEnter = "${path}mine_ai_enter.webp".holidayPath;

    _model.homeNor = "${path}home_0_0.webp".holidayPath;
    _model.homeSel = "${path}home_0_1.webp".holidayPath;

    _model.acgNor = "${path}home_1_0.webp".holidayPath;
    _model.acgSel = "${path}home_1_1.webp".holidayPath;

    _model.communityNor = "${path}home_2_0.webp".holidayPath;
    _model.communitySel = "${path}home_2_1.webp".holidayPath;

    _model.findNor = "${path}home_3_0.webp".holidayPath;
    _model.findSel = "${path}home_3_1.webp".holidayPath;

    _model.mineNor = "${path}home_4_0.webp".holidayPath;
    _model.mineSel = "${path}home_4_1.webp".holidayPath;

    switch (themeValue) {
      case 1:
        _model.tabSelColor = Colors.white.withOpacity(.9);
        _model.tabNorColor = Color(0xff464646);
        _model.searchBgColor = Colors.black.withOpacity(0.08);
        _model.searchTxColor = Color(0xff999999);
        _model.mainBg = "${path}main_bg.webp".holidayPath;
        _model.findBg = "${path}main_bg.webp".holidayPath;
        _model.mineBg = "${path}main_bg.webp".holidayPath;
        break;
      case 2:
        _model.tabSelColor = Color(0xff00BBB8);
        _model.tabNorColor = Color(0xff5D6573);
        _model.searchBgColor = Color(0xff41D0AB);
        _model.searchTxColor = Colors.white;
        _model.mainBg = "${path}main_bg.webp".holidayPath;
        _model.findBg = "${path}main_bg.webp".holidayPath;
        _model.mineBg = "${path}main_bg.webp".holidayPath;
        break;
      case 3:
        _model.tabSelColor = Color(0xff07738D);
        _model.tabNorColor = Color(0xff5D6573);
        _model.searchBgColor = Color(0xff8EC58E);
        _model.searchTxColor = Colors.white;
        _model.mainBg = "${path}main_bg.webp".holidayPath;
        _model.findBg = "${path}find_bg.webp".holidayPath;
        _model.mineBg = "${path}mine_bg.webp".holidayPath;

        break;
      case 4:
        _model.tabSelColor = Color(0xffBE0209);
        _model.tabNorColor = Color(0xff6C6C6C);
        _model.searchBgColor = Color(0xffD7221D);
        _model.searchTxColor = Colors.white;
        _model.mainBg = "${path}main_bg.webp".holidayPath;
        _model.findBg = "${path}main_bg.webp".holidayPath;
        _model.mineBg = "${path}main_bg.webp".holidayPath;
        break;
      case 5:
        _model.tabSelColor = Color(0xff3E64EA);
        _model.tabNorColor = Color(0xff95949a);

        _model.searchBgColor = Colors.black.withOpacity(0.08);
        _model.searchTxColor = Colors.white;
        break;
      case 6:
        _model.tabSelColor = Color(0xff3E64EA);
        _model.tabNorColor = Color(0xff95949a);

        _model.searchBgColor = Colors.black.withOpacity(0.08);
        _model.searchTxColor = Colors.white;
        break;
      case 7:
        _model.tabSelColor = Color(0xff3E64EA);
        _model.tabNorColor = Color(0xff95949a);

        _model.searchBgColor = Colors.black.withOpacity(0.08);
        _model.searchTxColor = Colors.white;
        break;
      case 8:
        _model.tabSelColor = Color(0xff3E64EA);
        _model.tabNorColor = Color(0xff95949a);

        _model.searchBgColor = Colors.black.withOpacity(0.08);
        _model.searchTxColor = Colors.white;
        break;
    }
  }

  void changeAppIcon() async {
    const platform = MethodChannel('samples.flutter.io/requestApi');
    if (themeValue == 1) {
      platform.invokeMethod('changeIcon', {"iconIndex": 0});
    } else if (themeValue == 2) {
      platform.invokeMethod('changeIcon', {"iconIndex": 16});
    } else if (themeValue == 3) {
      platform.invokeMethod('changeIcon', {"iconIndex": 17});
    } else if (themeValue == 4) {
      platform.invokeMethod('changeIcon', {"iconIndex": 18});
    }
  }

  int get iconIndex {
    if (themeValue == 1) return 0;
    if (themeValue == 2) return 16;
    if (themeValue == 3) return 17;
    if (themeValue == 4) return 18;
    return 0;
  }

  String get iconString {
    if (themeValue == 1) return 'com.hsjj.MainActivity';
    if (themeValue == 2) return 'com.hsjj.ic_launcher1';
    if (themeValue == 3) return 'com.hsjj.ic_launcher2';
    if (themeValue == 4) return 'com.hsjj.ic_launcher3';
    return 'com.hsjj.MainActivity';
  }
}

class HolidayThemeModel {
  late String appIcon;
  late int current;
  late String homeNor; //首页普通
  late String homeSel; //首页选中
  late String acgNor; //acg普通
  late String acgSel; //acg选中
  late String communityNor; //社区普通
  late String communitySel; //社区选中
  late String findNor; //发现普通
  late String findSel; //发现选中
  late String mineNor; //我的普通
  late String mineSel; //我的选中
  late String mainBg; //首页背景
  late String findBg; //首页背景
  late String mineBg; //首页背景

  late Color tabNorColor; //tabbar颜色
  late Color tabSelColor; //tabbar选中颜色
  late Color searchBgColor; //搜索框背景色
  late Color searchTxColor; //搜索颜色
  late String searchBgImg;
  late String vipBg; //会员背景
  late String addPublish; //添加发布

  late String coin; //金币
  late String agent; //分享
  late String aiEnter; //推广
}
